
import { util } from '../../../../utils/util';
var app = getApp();
//身心健康  体育竞赛
Page({
  mixins: [],
  data: {
     activityType:'',    //活动类型
     instanceType:'',       //实例类型
     honorDate:'',
     honorFiles:[], //图片数组
     //选择获奖类型
     honorType:'',
     gradeArr:[
        {css:'',id:'1',value:'国家级'},{css:'',id:'2',value:'省级'},{css:'',id:'3',value:'市级'},{css:'',id:'4',value:'县级'},{css:'',id:'5',value:'校级'}
    ],
    //开始选择时长
    start:util.formatDateTimeFive(new Date()),
       //结束时长
     end:util.formatDateTime(new Date()),
    },
    on_grade(e){
      var me = this;
      console.log(e.currentTarget.dataset.index)
      let index=e.currentTarget.dataset.index;
      let arr=me.data.gradeArr;
      let i=0;
      for(;i<arr.length;i++){arr[i].css=''}
      arr[index].css = ' active';
      me.data.honorType=arr[index].id;
      me.setData( me.data);
    },

    onSubmit(e) {
      var me = this;
      var obj = e.detail.value;
      var dataObj=obj;
      dataObj['honorType'] =me.data.honorType;
      //做非空校验
      if(util.validation(dataObj)){
          obj['honorType'] = parseInt(me.data.honorType);
          obj['files'] = me.data.honorFiles;
          obj['activityType'] = parseInt(me.data.activityType);
          obj['instanceType'] = parseInt(me.data.instanceType);
          obj['showName'] = 'competitionName';
          console.info(obj);
          var postdata = {
               activityType: parseInt(me.data.activityType),
               instanceType: parseInt(me.data.instanceType),
               itemInfo : obj,
               };
           //调用提交方法
          util.submitRecord(postdata); 
      } 
    },
  stateDatePickerYMDHMS: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      honorDate: e.detail.value
    })
  },
  onLoad(query) {
    // 页面加载
    console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
     var arr = query.honorFiles.split(",");
    this.setData({
      activityType: query.activityType,
      instanceType: query.instanceType,
      honorFiles: arr,
      honorType:'',
     gradeArr:[
        {css:'',id:'1',value:'国家级'},{css:'',id:'2',value:'省级'},{css:'',id:'3',value:'市级'},{css:'',id:'4',value:'县级'},{css:'',id:'5',value:'校级'}
    ]
    });
  },
  onUnload() {
    // 页面被关闭
    wx.setStorageSync("honorFiles", []);
  },
});
